
function ProgressBar() {
	this.html5_progress_bar_container = document.createElement('div');
	this.html5_progress_bar_container.setAttribute('class', 'html5-progress-bar-container html5-progress-bar');

	this.progress_bar_wrapper = document.createElement('div');
	this.progress_bar_wrapper.setAttribute('class', 'progress-bar-wrapper');
	this.html5_progress_bar_container.appendChild(this.progress_bar_wrapper);

	this.progress = document.createElement('progress');
	this.progress.setAttribute('value', '0');
	this.progress.setAttribute('max', '100');
	this.progress_bar_wrapper.appendChild(this.progress);

	this.progress_value = document.createElement('div');
	this.progress_value.setAttribute('class', 'progress-value');
	this.progress_value.appendChild(document.createTextNode('0%'));

	this.progress_bar_wrapper.appendChild(this.progress_value);

	this.show = function() {
		document.getElementsByTagName('body')[0].appendChild(this.html5_progress_bar_container);
	};
	this.remove = function() {
		document.getElementsByTagName('body')[0].removeChild(this.html5_progress_bar_container);
	};
	this.setValue = function(value) {
		this.progress.value = Math.round(value);
		this.progress_value.innerHTML = Math.round(value) + "%";
	};
};

function ajaxPost() {
	var progressBar = new ProgressBar();

	var ajax = new XMLHttpRequest();

	var fadeOverlay = document.createElement('div');
	fadeOverlay.setAttribute('id', 'fullhappy_light_box_fade');
	fadeOverlay.setAttribute('class', 'fullhappy_light_box_fade');

	this.open = function(method, url) {
		ajax.open(method, url);
	};
	this.send = function(formdata) {
		ajax.send(formdata);
	};
	var loadStartHandler = function(event) {
		document.getElementsByTagName('body')[0].appendChild(fadeOverlay);
		progressBar.show();
	};
	var progressHandler = function(event) {
		var percent = (event.loaded / event.total) * 100;
		progressBar.setValue(percent);
	};
	var loadEndHandler = function(event) {
		progressBar.remove();
		document.getElementsByTagName('body')[0].removeChild(fadeOverlay);
	};

	ajax.upload.addEventListener("loadstart", loadStartHandler, false);
	ajax.upload.addEventListener("progress", progressHandler, false);
	ajax.upload.addEventListener("loadend", loadEndHandler, false);
}